package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarBrand;


@Repository("carBrandDAO")
public class CarBrandDAOImpl implements CarBrandDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarBrand carBrand) {
		sessionFactory.getCurrentSession().saveOrUpdate(carBrand);
		
	}

	@Override
	public void delete(int id) {
		CarBrand carBrand = (CarBrand) sessionFactory.getCurrentSession().get(CarBrand.class, id);
		sessionFactory.getCurrentSession().delete(carBrand);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarBrand> findAll() {
		
		return (List<CarBrand>) sessionFactory.getCurrentSession().createCriteria(CarBrand.class).list();
	}

	@Override
	public CarBrand findById(int id) {

		return (CarBrand) sessionFactory.getCurrentSession().get(CarBrand.class, id);
	}

}
